package _30define;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.text.Annotation;

@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Config {
    String value();
}
interface Inter{
    @Config("0111")
    void displayConfig();
}

class MyClass implements Inter{
    @Config("application")
    private String configValue;
    public MyClass(){
    }
    @Override
    public void displayConfig() {
        System.out.println ("Config Value: " + configValue);
    }
}
class ConfigReader{
    public static void main(String[] args) throws Exception {
        Class<?> c=Class.forName("_30define.MyClass");
        Annotation[] annotations = (Annotation[]) c.getAnnotations ();
        for (Annotation annotation : annotations) {
            if (annotation.equals(Config.class)){
                Config config=(Config) annotation;
                System.out.println ("Value: " + config.value ());
                break;
            }
        }
        Method method= c.getMethod("displayConfig");
        method.invoke(c.newInstance());
    }
}
